// 获取tbody
var myTbody = document.getElementById("myTbody");
var add = document.getElementsByClassName("add")[0];
var modify = document.getElementsByClassName("modify")[0];
var inps = document.getElementsByClassName("inp")[0];
var seek = document.getElementsByClassName("seek")[0];
seek.onclick = function () {
    myTbody.innerHTML = "";
    fileManagerList();
    console.log(111);
}



// // 封装详情函数
// // 
// function detailUser(id) {
//     // 获取详情按钮
//     // 
//     var detail = document.querySelectorAll('.detail');
//     // 遍历详情按钮，添加点击事件
//     // 
//     for (var i = 0; i < detail.length; i++) {
//         detail[i].onclick = function () {
//             // 添加蒙版
//             // 
//             var right = document.querySelector(".rightstudentB");
//             var mask = document.createElement('div');
//             mask.className = "mask";
//             right.appendChild(mask);
//             // 调取数据，添加模态框
//             // 
//             var date = {
//                 fileManagerId: id,
//             }
//             obj.post("http://192.168.199.101:8080/BaorSystem/fileManager/fileManagerInfo", date, function (res) {
//                 if (res.code == 200) {
//                     console.log("详情", res);
//                     pageCount = res.fileManagerList.pageCount;
//                     for (var item of res.fileManagerList.fileManagerList) {
//                         var right = document.querySelectorAll(".rightstudentB")[0];
//                         var rightmodl = document.querySelector(".rightmodl");
//                         rightmodl.style.display = 'block'
//                         rightmodl.innerHTML = `
//                                     <div class="head1">
//                                             <span>添加在习生</span>
//                                     </div>
//                                     <div class="body1">
//                                         <span class="span1">姓名: </span>
//                                         <span class="fileManagerName1" type="text">${item.fileManagerName}</span>
//                                         <span class="span2">班级： </span>
//                                         <span class="clazzName1" type="text">${item.clazzName}</span>
//                                         <span class="span3">性别： </span>
//                                         <span class="fileManagerSex1">${item.fileManagerSex}</span>
//                                         <span class="span4">毕业日期： </span>
//                                         <span class="fileManagerDate1" >${item.fileManagerDate}</span>
//                                         <span class="span5">电话： </span>
//                                         <span class="fileManagerPhone1" type="text">${item.fileManagerPhone}</span>
//                                         <span class="span9">家庭地址： </span>
//                                         <span class="fileManagerAddress1" type="text"> ${item.fileManagerAddress}</span>
//                                         <span class="span6">紧急联系人： </span>
//                                         <span class="fileManagerSosperson1" type="text"> ${item.fileManagerSosperson}</span>
//                                         <span class="span7">紧急联系人电话： </span>
//                                         <span class="fileManagerSosphone1" type="text"> ${item.fileManagerSosphone}</span>
//                                         <span class="span8">账号： </span>
//                                         <span class="fileManagerAccount1" >${item.fileManagerName}</span>
//                                     </div>
//                                     <div class="foot1">
//                                             <button class="btn btn1">确认<[表情]tton>
//                                             <button class="btn btn2">取消<[表情]tton>
//                                     </div>
//                                 `;
//                     }
//                     // 点击取消和确定
//                     var btn = document.querySelectorAll('.btn');
//                     console.log(btn);
//                     for (var item0 of btn) {
//                         item0.onclick = function () {
//                             right.removeChild(mask);
//                             rightmodl.innerHTML = "";
//                             rightmodl.style.display = 'none';
//                         }
//                     }
//                 }
//             })
//         }
//     }
// }






// 点击添加，出现motaikuang
add.onclick = function () {
    // 调用myModel
    myModel({
        mask: true,//显示蒙版
        //标题
        content_item1: `
        <div class="title">添加在习生</div>
                    <div class="userupdate">
                        
                        <div class="left">
                            <div class="name">姓名：<input type="text" id="username"></div>
                        <div class="sex">性别：<select name="" id="usersex">
                                <option value="男">男</option>
                                <option value="男">女</option>
                            </select>
                            </div>
                        <div class="phone">电话：<input type="text" id="userphone"></div>
                        <div class="sosuser">紧急联系人：<input type="text" id="sosUser"></div>
                        <div class="account">账号：<input type="text" id="useraccount" ></div>
                        </div>
                        <div class="right">
                            <div class="class">班级：<select name="" id="Class">
                                <option value="0">UI设计</option>
                                <option value="1">前端开发</option>
                                <option value="2">后端开发</option>
                            </select></div>
                        <div class="date">毕业日期：<input type="text" id="Date"></div>
                        <div class="address">家庭地址：<input type="text" id="Address"></div>
                        <div class="sosphone">紧急联系人电话：<input type="text" id="sosPhone"></div>
                        </div>
                    </div>
                `,
        fun: function () {
            // 执行添加的函数
            addUser()
        }
    })
}

// 封装用户列表渲染
function fileManagerList() {
    var pageIndex = 1;
    var pageSize = 6;
    // var pageCount = 0;
    // 调接口
    var data = {
        pageSize: pageSize,
        pageIndex: pageIndex,
        fileManagerType: "在习生",
        fileManagerName: inps.value
    }
    ajax.post("http://192.168.199.101:8080/BaorSystem/fileManager/fileManagerList", data, function (res) {
        if (res.code == 200) {
            var fileManagerList = res.dataset;
            // 当用户列表重新渲染时，用户列表需清空
            myTbody.innerHTML = " ";
            // 获取总页数
            pageCount = fileManagerList.pageCount;
            // 获取用户列表进行页面渲染
            for (var i = 0; i < fileManagerList.fileManagerList.length; i++) {
                var newTr = document.createElement("tr");
                newTr.innerHTML = `
                      <td>${res.dataset.fileManagerList[i].fileManagerName}</td>
                         <td>${res.dataset.fileManagerList[i].fileManagerSex}</td>
                         <td>${res.dataset.fileManagerList[i].clazzName}</td>
                         <td>${res.dataset.fileManagerList[i].fileManagerDate}</td>
                         <td>${res.dataset.fileManagerList[i].fileManagerPhone}</td>
                         <td>${res.dataset.fileManagerList[i].fileManagerStatus}</td>
                        <td>
                            <button class="modify" onclick="modifyUser(${fileManagerList.fileManagerList[i].fileManagerId})">修改</button>
                            <button class="del" onclick="delUser(${fileManagerList.fileManagerList[i].fileManagerId})">删除</button>
                        </td>
                        <td><button class="detail">详情</button></td>
                    `
                myTbody.appendChild(newTr)
            }
            console.log(fileManagerList, pageCount);
        }
    })
}
fileManagerList()
// 封装删除
function delUser(id) {
    // 调接口
    ajax.post(`http://192.168.199.101:8080/BaorSystem/fileManager/deleteFileManager`, { fileManagerId: id }, function (res) {
        if (res.code == 200) {
            alert("该用户删除成功");
            // 重新渲染用户列表
            fileManagerList()
        }
    })
}
// 封装添加
function addUser() {
    //  调添加用户接口
    var data = {
        fileManagerType: "在习生",
        fileManagerName: document.getElementById("username").value,
        fileManagerSex: document.getElementById("usersex").value,
        fileManagerPhone: document.getElementById("userphone").value,
        fileManagerSosperson: document.getElementById("sosUser").value,
        fileManagerAccount: document.getElementById("useraccount").value,
        clazzId: Number(document.getElementById("Class").value),
        fileManagerDate: document.getElementById("Date").value,
        fileManagerAddress: document.getElementById("Address").value,
        fileManagerSosphone: document.getElementById("sosPhone").value,
    }
    ajax.post('http://192.168.199.101:8080/BaorSystem/fileManager/addFileManager', data, function (res) {
        console.log(res);
        fileManagerList();
    })

}

// 封装修改
function modifyUser(userId) {
    // 模态框显示
    myModel({
        mask: true,//显示蒙版
        content_item1: `
                    <div class="title">修改在习生</div>
                    <div class="userupdate">

                        <div class="left">
                            <div class="name">姓名：<input type="text" id="username"></div>
                        <div class="sex">性别：<select name="" id="sosUser">
                                <option value="男">男</option>
                                <option value="女">女</option>
                            </select></div>
                        <div class="phone">电话：<input type="text" id="userphone"></div>
                        <div class="sosuser">紧急联系人：<input type="text" id="usersex">
                        </div>
                        <div class="account">账号：<input type="text" id="useraccount" ></div>
                        </div>
                        <div class="right">
                            <div class="class">班级：<select name="" id="Class">
                                <option value="0">UI设计</option>
                                <option value="1">前端开发</option>
                                <option value="2">后端开发</option>
                            </select></div>
                        <div class="date">毕业日期：<input type="date" id="Date"></div>
                        <div class="address">家庭地址：<input type="text" id="Address"></div>
                        <div class="sosphone">紧急联系人电话：<input type="text" id="sosPhone"></div>
                        </div>
                    </div>
                `,
        fun: function () {
            var data = {

            }
            ajax.post("http://192.168.199.101:8080/BaorSystem/fileManager/updateFileManager", { fileManagerId: id }, function (res) {
                if (res.code == 200) {
                    console.log(res);
                    alert('当前用户修改成功');
                    fileManagerList();
                }
            })
        }
    })
}
var journal = document.getElementsByClassName("journal")[0];
journal.onclick = function () {
    location.href = "./diary.html";
}
//审核系统
var vet = document.getElementsByClassName("vet")[0];
vet.onclick = function () {
    location.href = "./audit.html";
}
//用户管理
var user = document.getElementsByClassName("user")[0];
user.addEventListener('click', function () {
    location.href = "./UserMage.html";
});
//班级管理
var classs = document.getElementsByClassName("classs");
classs[0].onclick = function () {
    location.href = "./ClassManagement.html";
}
//日常
var routine = document.getElementsByClassName("routine")[0];
routine.onclick = function () {
    location.href = "./daily.html";
}
//学生档案
var archives = document.getElementsByClassName("archives")[0];
archives.onclick = function () {
    location.href = "./student file.html";
}
//项目管理
var project = document.getElementsByClassName("project")[0];
project.onclick = function () {
    location.href = "./projectmanagement.html";
}
//出差记录
var travel = document.querySelector(".travel");
travel.addEventListener('click', function () {
    location.href = "./business.html";
});
//请假记录
var excused = document.querySelector(".excused");
excused.addEventListener('click', function () {
    location.href = "./vacate.html";
});
//考勤记录
var presence = document.querySelector(".presence");
presence.addEventListener('click', function () {
    location.href = "./clock.html";
});